﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Diagnostics.Contracts;

namespace Watson.TemporaryFilesDeleter.Util
{
    /// <summary>
    /// Provides helper methods working with Windows Explorer.
    /// </summary>
    public static class ExplorerUtil
    {
        /// <summary>
        /// Opens Windows Explorer at the specified path.
        /// </summary>
        /// <param name="path">
        /// The path to show in Windows Explorer.
        /// </param>
        /// <exception cref="System.ArgumentNullException">
        /// <paramref name="path"/> was null.
        /// </exception>
        /// <exception cref="System.ArgumentException">
        /// <paramref name="path"/> was a zero-length string or consisted
        /// entirely of whitespace.
        /// </exception>
        public static void OpenExplorer(string path)
        {
            if (path == null)
                throw new ArgumentNullException("path");
            
            if (String.IsNullOrWhiteSpace(path))
                throw new ArgumentException(
                    "Value cannot be a zero-length string or consist entirely"
                    + " of whitespace.", "path");
            

            /*
             * Start Windows Explorer in the specified path.
             */
            Process process = new Process();
            
            process.StartInfo.UseShellExecute = true;
            
            process.StartInfo.FileName = "explorer";
            process.StartInfo.Arguments = path;

            process.Start();
        }
    }
}
